storing.inds <- function (folder, channels = NULL, fourier = TRUE, saturated = TRUE,
          lets.pullup = TRUE)
{
  coli <- c("cornflowerblue", "chartreuse4", "gold2", "red",
            "orange", "purple")
  curdir <- getwd()
  setwd(paste(folder))
  listp2 <- dir(folder, "*.fsa")
  all.inds.mats <- list(NA)
  #print("Reading FSA files")
  count <- 0
  tot <- length(listp2)
  #pb <- txtProgressBar(style = 3)
  #setTxtProgressBar(pb, 0)
  for (i in 1:length(listp2)) {
    count <- count + 1
    # import read.abif
    fsaFile <- read.abif(listp2[i])
    lens <- lapply(fsaFile$Data, length)
    aaa <- table(unlist(lens))
    if (is.null(channels)) {
      channels <- as.vector(aaa[which(as.numeric(names(aaa)) >
                                        1000)])
    }
    real.len <- as.numeric(names(aaa)[which(aaa == channels & as.numeric(names(aaa)) > 1000)])
    v <- as.vector(which(unlist(lens) == real.len))
    reads <- list(NA)
    for (j in 1:channels) {
      v2 <- v[j]
      reads[[j]] <- fsaFile$Data[[v2]]
    }
    all.inds.mats[[i]] <- matrix(unlist(reads), ncol = channels)
    names(all.inds.mats)[i] <- as.character(listp2[i])
    #setTxtProgressBar(pb, count/tot)
  }
  #close(pb)
  # import lapple_pd
  if (fourier == TRUE) {
    #print("Applying Fourier tranformation for smoothing...")
    all.inds.mats <- lapply_pb(all.inds.mats, function(x) {
      # import transfft
      apply(x, 2, transfft)
    })
  }
  if (saturated == TRUE) {
    #print("Checking and correcting for saturated peaks...")
    all.inds.mats <- lapply_pb(all.inds.mats, function(x) {
      # import saturate
      apply(x, 2, saturate)
    })
  }
  if (lets.pullup == TRUE) {
    #print("Applying pull up correction to the samples to decrease noise from channel to channel")
    # import pullup
    all.inds.mats <- lapply_pb(all.inds.mats, pullup, channel = channels)
  }
  #layout(matrix(1, 1, 1))
  setwd(curdir)
  return(all.inds.mats)
}
